package com.ed.controller;

import com.ed.domain.Faq;
import com.ed.dto.AnswerQDTO;
import com.ed.dto.PageQueryDto;
import com.ed.dto.SubmitDto;
import com.ed.result.PageResult;
import com.ed.result.Result;
import com.ed.service.IFaqQuestionService;
import com.ed.task.AnswerQuesTask;
import com.ed.vo.QuesVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Faq")
@CrossOrigin
public class FaqQuestionController {

    @Autowired
    private IFaqQuestionService faqQuestionService;




    /**
     * 增加 FAQ 题目
     * @param faq
     * @return
     */
    @PostMapping("/AddFaq")
    public Result AddFaq(@RequestBody Faq faq) {
        faqQuestionService.AddFaq(faq);
        return Result.success();
    }

    /**
     * 删除 FAQ 题目
     * @param id
     * @return
     */
    @DeleteMapping("/DeleteFaq")
    public Result DeleteFaq(Integer id) {
        faqQuestionService.DeleteFaq(id);
        return Result.success();
    }

    /**
     * 更新 FAQ 题目
     * @param faq
     * @return
     */
    @PutMapping("/UpdateFaq")
    public Result UpdateFaq(@RequestBody Faq faq) {
        faqQuestionService.UpdateFaq(faq);
        return Result.success();
    }

    /**
     * 查询 FAQ 题目和选项
     * @param id
     * @return
     */
    @GetMapping("/GetFaq")
    public Result<QuesVO> GetFaq(Integer id) {
        QuesVO quesVO = faqQuestionService.getFaq(id);
        return Result.success(quesVO);
    }

    /**
     * 查询所有 FAQ 题目和选项
     * @return
     */
    @GetMapping("/GetFaqs")
    public Result<List<QuesVO>> GetFaqs() {
        List<QuesVO> quesVOS = faqQuestionService.getFaqs();
        return Result.success(quesVOS);
    }

    /**
     * FAQ 分页查询
     * @param pageQueryDto
     * @return
     */
    @GetMapping("/PageQuery")
    public Result<PageResult> PageQuery(PageQueryDto pageQueryDto) {
        PageResult pageResult = faqQuestionService.PageQuery(pageQueryDto);
        return Result.success(pageResult);
    }

    /**
     * 计算分数
     * @param submitDto
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody SubmitDto submitDto) {
        log.info("提交的题目：{}", submitDto);
        Integer score = faqQuestionService.calculateScore(submitDto);
        return Result.success(score);
    }
}
